#include "TranslateBoard.h"

TranslateBoard::TranslateBoard(GamesHistory * hist) {
    for(int i = 0; i < 8; ++i) {
        for(int k = 0; k < 8; ++k) {
            board[i][k] = empty;
        }
    }
    for(int i = 0; i < 32; ++i) {
        figures[i] = "00";
    }
    history = hist;
}

void TranslateBoard::init() {
    for(int i = 0; i < 8; ++i) {
        for(int k = 0; k < 8; ++k) {
            board[i][k] = empty;
        }
    }

    board[0][0] = r1;
    board[0][1] = n1;
    board[0][2] = b1;
    board[0][3] = q;
    board[0][4] = k;
    board[0][5] = b2;
    board[0][6] = n2;
    board[0][7] = r2;

    board[1][0] = p1;
    board[1][1] = p2;
    board[1][2] = p3;
    board[1][3] = p4;
    board[1][4] = p5;
    board[1][5] = p6;
    board[1][6] = p7;
    board[1][7] = p8;

    board[6][0] = P1;
    board[6][1] = P2;
    board[6][2] = P3;
    board[6][3] = P4;
    board[6][4] = P5;
    board[6][5] = P6;
    board[6][6] = P7;
    board[6][7] = P8;

    board[7][0] = R1;
    board[7][1] = N1;
    board[7][2] = B1;
    board[7][3] = Q;
    board[7][4] = K;
    board[7][5] = B2;
    board[7][6] = N2;
    board[7][7] = R2;

    for (int i = 0; i < 8; ++i){
        figures[i] = toString(i) + "8";
        figures[8 + i] = toString(i) + "7";
        figures[2*8 + i] = toString(i) + "2";
        figures[3*8 + i] = toString(i) + "1";
    }
}

void TranslateBoard::translate() {
//    int gamesCount = 1;
//    int gameNum = 0;
//    for (int i = gameNum; i < gameNum + gamesCount; ++i) {

    int gamesCount = history->getGames()->count();
    qDebug() << gamesCount << "gry:";
    for (int i = 0; i < gamesCount; ++i) {
        init();
        int movesCount = history->getGames()->at(i)->getGameMoves()->getMoves()->count();
        QString readGame = "Gra nr. " + QString::number(i+1) + " - " + QString::number(movesCount) + " ruchów w grze.";
        qDebug() << readGame;
        Console::print(readGame);
        for (int k = 0; k < movesCount; ++k) {
            int n = k + 1;
            Move * current = history->getGames()->at(i)->getGameMoves()->getMoves()->at(k);
            QString readMove= "------------ Ruch " + QString::number(n) + ": " + current->getName();
//            qDebug() << readMove;
            Move * currentMoveTranslated;
            try{
                if ((current->getName().left(1) >= "a" ) && (current->getName().left(1) < "i")) {
                    currentMoveTranslated = movePawn(k, current);
                } else if (current->getName().left(1) == "R") {
                    currentMoveTranslated = moveRook(k, current);
                } else if (current->getName().left(1) == "N") {
                    currentMoveTranslated = moveKnight(k, current);
                } else if (current->getName().left(1) == "B") {
                    currentMoveTranslated = moveBishop(k, current);
                } else if (current->getName().left(1) == "Q") {
                    currentMoveTranslated = moveQueen(k, current);
                } else if (current->getName().left(1) == "K") {
                    currentMoveTranslated = moveKing(k, current);
                } else if (current->getName().left(1) == "O") {
                    currentMoveTranslated = castling(k, current);
                } else {
                    qDebug() << "ruch" << n << "w grze" << i << "- do sprawdzenia";
                }
            }
            catch (int exc) {
                qDebug() << "Move" << n << "exception:";
                if (exc == -1) {
                    qDebug() << "String to int translating error";
                } else
                if (exc == -2) {
                    qDebug() << "Square is not empty";
                    Console::print(readMove);
                    Console::print("Pole docelowe nie jest puste.");
                } else
                if (exc == -3) {
                    qDebug() << "Nothing to capture";
                    Console::print(readMove);
                    Console::print("Brak figury do bicia na polu docelowym.");
                } else
                    {qDebug() << "Unknown Exception";}
            }
            history->getGames()->at(i)->getGameMoves()->getMoves()->at(k)->addSquare(currentMoveTranslated->getSquareBegin(), currentMoveTranslated->getSquareEnd(),currentMoveTranslated->getCastlingBegin(), currentMoveTranslated->getCastlingEnd());
//            debug(board);
        }
    }
    return;
}

int TranslateBoard::toInt(QString string) {
    if (string.length() > 1) string = string.left(1);
    if (string == "a") return 0;
    if (string == "b") return 1;
    if (string == "c") return 2;
    if (string == "d") return 3;
    if (string == "e") return 4;
    if (string == "f") return 5;
    if (string == "g") return 6;
    if (string == "h") return 7;
    return -1;
}

QString TranslateBoard::toString(int integer) {
    if (integer == 0) return "a";
    if (integer == 1) return "b";
    if (integer == 2) return "c";
    if (integer == 3) return "d";
    if (integer == 4) return "e";
    if (integer == 5) return "f";
    if (integer == 6) return "g";
    if (integer == 7) return "h";
    return -1;
}

Move * TranslateBoard::movePawn(int moveNum, Move * move) {
    bool ok;
    QString name;
    int len = move->getName().length();
    if (move->getName().right(1) == "+") {
        --len;
        name = move->getName().left(len);
    } else {
        name = move->getName();
    }
    if (len == 2) {
        int newA = toInt(name);
        int newL = 8 - name.right(1).toInt(&ok, 10);
        if (ok == false) {
            throw -1;
        }
        if (board[newL][newA] == empty) {
            if (move->getColor() == "black") {
                for (int i = p1; i <= p8; ++i) {
                    int oldA = toInt(figures[i]);
                    int oldL = 8-figures[i].right(1).toInt(&ok, 10);
                    if (ok == false) {
                        throw -1;
                    }
                    if ((oldA == newA) && ((newL - oldL == 1) || ((newL - oldL == 2) && (board[oldL+1][oldA] == empty)))) {
                        board[oldL][oldA] = empty;
                        board[newL][newA] = i;
                        figures[i] = name.right(2);
                        QString sqBeg = toString(oldA) + QString::number(8 - oldL);
                        QString sqEnd = toString(newA) + QString::number(8 - newL);
                        Move * translatedMove = new Move(moveNum, move->getColor(), move->getName(), sqBeg, sqEnd);
                        return translatedMove;
                    }
                }
            } else {
                for (int i = P1; i <= P8; ++i) {
                    int oldA = toInt(figures[i]);
                    int oldL = 8-figures[i].right(1).toInt(&ok, 10);
                    if ((oldA == newA) && ((oldL - newL == 1) || (oldL - newL == 2) && (board[oldL-1][oldA] == empty))) {
                        board[oldL][oldA] = empty;
                        board[newL][newA] = i;
                        figures[i] = name.right(2);
                        QString sqBeg = toString(oldA) + QString::number(8 - oldL);
                        QString sqEnd = toString(newA) + QString::number(8 - newL);
                        Move * translatedMove = new Move(moveNum, move->getColor(), move->getName(), sqBeg, sqEnd);
                        return translatedMove;
                    }
                }
            }
        }
        else {
            throw -2;
        }
    }
    if (len == 4) {
        int newA = toInt(name.right(2));
        int newL = 8 - name.right(1).toInt(&ok, 10);
        if (ok == false) {
            throw -1;
        }
        if (board[newL][newA] == empty) {
            throw -3;
        } else {
            if (move->getColor() == "black") {
                for (int i = p1; i <= p8; ++i) {
                    int oldA = toInt(figures[i]);
                    int oldL = 8-figures[i].right(1).toInt(&ok, 10);
                    if (ok == false) {
                        throw -1;
                    }
                    if (((oldA == newA - 1) || (oldA == newA + 1)) && (newL - oldL == 1) && (figures[i].at(0) == name.at(0))) {
                        if (board[newL][newA] > empty) figures[board[newL][newA]] = "00";
                        board[oldL][oldA] = empty;
                        board[newL][newA] = i;
                        figures[i] = name.right(2);
                        QString sqBeg = toString(oldA) + QString::number(8 - oldL);
                        QString sqEnd = toString(newA) + QString::number(8 - newL);
                        Move * translatedMove = new Move(moveNum, move->getColor(), move->getName(), sqBeg, sqEnd);
                        return translatedMove;
                    }
                }
            } else {
                for (int i = P1; i <= P8; ++i) {
                    int oldA = toInt(figures[i]);
                    int oldL = 8-figures[i].right(1).toInt(&ok, 10);
                    if (ok == false) {
                        throw -1;
                    }
                    if (((oldA == newA - 1) || (oldA == newA + 1)) && (oldL - newL == 1) && (figures[i].at(0) == name.at(0))) {
                        if (board[newL][newA] > empty) figures[board[newL][newA]] = "00";
                        board[oldL][oldA] = empty;
                        board[newL][newA] = i;
                        figures[i] = name.right(2);
                        QString sqBeg = toString(oldA) + QString::number(8 - oldL);
                        QString sqEnd = toString(newA) + QString::number(8 - newL);
                        Move * translatedMove = new Move(moveNum, move->getColor(), move->getName(), sqBeg, sqEnd);
                        return translatedMove;
                    }
                }
            }
        }
    }
    throw -4;
}

Move * TranslateBoard::moveRook(int moveNum, Move *move) {
    bool ok;
    QString name;
    int len = move->getName().length();
    if (move->getName().right(1) == "+") {
        --len;
        name = move->getName().left(len);
    } else {
        name = move->getName();
    }
    int newA = toInt(name.right(2));
    int newL = 8 - name.right(1).toInt(&ok, 10);
    if (ok == false)  {
        throw -1;
    }
    if ((name.at(len-3) == "x") && board[newL][newA] == empty) {
        throw -3;
    }
    if (!(name.at(len-3) == "x") && !(board[newL][newA] == empty)) {
        throw -2;
    }
    if (move->getColor() == "black") {
        for (int i = r1; i <= r2; i = i + r2 - r1) {
            int oldA = toInt(figures[i]);
            int oldL = 8-figures[i].right(1).toInt(&ok, 10);
            if (ok == false)  {
                throw -1;
            }
            if ((len == 4) && !(name.at(1) == "x") && ((figures[i].at(0) != name.at(1)) && (figures[i].at(1) != name.at(1)))) {
                continue;
            }
            if ((len == 5) && (name.at(2) == "x") && (name.at(1) != figures[i].at(0))) {
                continue;
            }
            if (checkRook(oldL, oldA, newL, newA)) {
                if (board[newL][newA] > empty) figures[board[newL][newA]] = "00";
                board[oldL][oldA] = empty;
                board[newL][newA] = i;
                figures[i] = name.right(2);
                QString sqBeg = toString(oldA) + QString::number(8 - oldL);
                QString sqEnd = toString(newA) + QString::number(8 - newL);
                Move * translatedMove = new Move(moveNum, move->getColor(), move->getName(), sqBeg, sqEnd);
                return translatedMove;
            }
        }
    } else {
        for (int i = R1; i <= R2; i = i + R2 - R1) {
            int oldA = toInt(figures[i]);
            int oldL = 8-figures[i].right(1).toInt(&ok, 10);
            if (ok == false)  {
                throw -1;
            }
            if ((len == 4) && !(name.at(1) == "x") && ((figures[i].at(0) != name.at(1)) && (figures[i].at(1) != name.at(1)))) {
                continue;
            }
            if ((len == 5) && (name.at(2) == "x") && (name.at(1) != figures[i].at(0))) {
                continue;
            }
            if (checkRook(oldL, oldA, newL, newA)) {
                if (board[newL][newA] > empty) figures[board[newL][newA]] = "00";
                board[oldL][oldA] = empty;
                board[newL][newA] = i;
                figures[i] = name.right(2);
                QString sqBeg = toString(oldA) + QString::number(8 - oldL);
                QString sqEnd = toString(newA) + QString::number(8 - newL);
                Move * translatedMove = new Move(moveNum, move->getColor(), move->getName(), sqBeg, sqEnd);
                return translatedMove;
            }
        }
    }
    throw -4;
}

bool TranslateBoard::checkRook(int oldL, int oldA, int newL, int newA) {
    if (!(oldA == newA) && !(oldL == newL )) {
        return false;
    }
    if (oldA == newA) {
        if (oldL > newL) {
            for (int i = newL + 1; i < oldL; i++) {
                if (board[i][oldA] != empty) {
                    return false;
                }
            }
            return true;
        } else {
            for (int i = oldL + 1; i < newL; i++) {
                if (board[i][oldA] != empty) {
                    return false;
                }
            }
            return true;
        }
    } else {
        if (oldA > newA) {
            for (int i = newA + 1; i < oldA; i++) {
                if (board[oldL][i] != empty) {
                    return false;
                }
            }
            return true;
        } else {
            for (int i = oldA + 1; i < newA; i++) {
                if (board[oldL][i] != empty) {
                    return false;
                }
            }
            return true;
        }
    }
}

Move * TranslateBoard::moveKnight(int moveNum, Move *move) {
    bool ok;
    QString name;
    int len = move->getName().length();
    if (move->getName().right(1) == "+") {
        --len;
        name = move->getName().left(len);
    } else {
        name = move->getName();
    }
    int newA = toInt(name.right(2));
    int newL = 8 - name.right(1).toInt(&ok, 10);
    if (ok == false)  {
        throw -1;
    }
    if (((name.at(len-3) == "x") || (name.at(2) == "x")) && (board[newL][newA] == empty)) {
        throw -3;
    }
    if ((!(name.at(len-3) == "x") && !(name.at(2) == "x")) && !(board[newL][newA] == empty)) {
        throw -2;
    }
    if (move->getColor() == "black") {
        for (int i = n1; i <= n2; i = i + n2 - n1) {
            int oldA = toInt(figures[i]);
            int oldL = 8-figures[i].right(1).toInt(&ok, 10);
            if (ok == false)  {
                throw -1;
            }
            if ((len == 4) && (!(name.at(1) == "x") && !(name.at(2) == "x")) && (figures[i].at(0) != name.at(1)) && (figures[i].at(1) != name.at(1))) {
                continue;
            }
            if ((((oldA == newA + 1) || (oldA == newA - 1)) && ((oldL == newL + 2) || (oldL == newL - 2))) ||
                (((oldA == newA + 2) || (oldA == newA - 2)) && ((oldL == newL + 1) || (oldL == newL - 1)))){
                if (board[newL][newA] > empty) figures[board[newL][newA]] = "00";
                board[oldL][oldA] = empty;
                board[newL][newA] = i;
                figures[i] = name.right(2);
                QString sqBeg = toString(oldA) + QString::number(8 - oldL);
                QString sqEnd = toString(newA) + QString::number(8 - newL);
                Move * translatedMove = new Move(moveNum, move->getColor(), move->getName(), sqBeg, sqEnd);
                return translatedMove;
            }
        }
    } else {
        for (int i = N1; i <= N2; i = i + N2 - N1) {
            int oldA = toInt(figures[i]);
            int oldL = 8-figures[i].right(1).toInt(&ok, 10);
            if (ok == false)  {
                throw -1;
            }
            if ((len == 4) && (!(name.at(1) == "x") && !(name.at(2) == "x")) && (figures[i].at(0) != name.at(1)) && (figures[i].at(1) != name.at(1))) {
                continue;
            }
            if (((oldA == newA + 1) || (oldA == newA - 1)) && ((oldL == newL + 2) || (oldL == newL - 2)) ||
                ((oldA == newA + 2) || (oldA == newA - 2)) && ((oldL == newL + 1) || (oldL == newL - 1))){
                if (board[newL][newA] > empty) figures[board[newL][newA]] = "00";
                board[oldL][oldA] = empty;
                board[newL][newA] = i;
                figures[i] = name.right(2);
                QString sqBeg = toString(oldA) + QString::number(8 - oldL);
                QString sqEnd = toString(newA) + QString::number(8 - newL);
                Move * translatedMove = new Move(moveNum, move->getColor(), move->getName(), sqBeg, sqEnd);
                return translatedMove;
            }
        }
    }
    throw -4;
}

Move * TranslateBoard::moveBishop(int moveNum, Move *move) {
    bool ok;
    QString name;
    int len = move->getName().length();
    if (move->getName().right(1) == "+") {
        --len;
        name = move->getName().left(len);
    } else {
        name = move->getName();
    }
    int newA = toInt(name.right(2));
    int newL = 8 - name.right(1).toInt(&ok, 10);
    if (ok == false)  {
        throw -1;
    }
    if ((name.at(len-3) == "x") && (board[newL][newA] == empty)) {
        throw -3;
    }
    if (!(name.at(len-3) == "x") && !(board[newL][newA] == empty)) {
        throw -2;
    }
    if (move->getColor() == "black") {
        for (int i = b1; i <= b2; i = i + b2 - b1) {
            int oldA = toInt(figures[i]);
            int oldL = 8-figures[i].right(1).toInt(&ok, 10);
            if (ok == false)  {
                throw -1;
            }
            if ((len == 4) && !(name.at(1) == "x") && (figures[i].at(0) != name.at(1))) {
                continue;
            }
            if (figures[i] == "00") {
                continue;
            }
            if ((oldA - newA == oldL - newL) || (oldA - newA == newL - oldL) ||
                    (newA - oldA == newL - oldL) || (newA - oldA == oldL - newL)){
                if (board[newL][newA] > empty) figures[board[newL][newA]] = "00";
                board[oldL][oldA] = empty;
                board[newL][newA] = i;
                figures[i] = name.right(2);
                QString sqBeg = toString(oldA) + QString::number(8 - oldL);
                QString sqEnd = toString(newA) + QString::number(8 - newL);
                Move * translatedMove = new Move(moveNum, move->getColor(), move->getName(), sqBeg, sqEnd);
                return translatedMove;
            }
        }
    } else {
        for (int i = B1; i <= B2; i = i + B2 - B1) {
            int oldA = toInt(figures[i]);
            int oldL = 8-figures[i].right(1).toInt(&ok, 10);
            if (ok == false)  {
                throw -1;
            }
            if ((len == 4) && !(name.at(1) == "x") && (figures[i].at(0) != name.at(1))) {
                continue;
            }
            if ((oldA - newA == oldL - newL) || (oldA - newA == newL - oldL) ||
                    (newA - oldA == newL - oldL) || (newA - oldA == oldL - newL)){
                if (board[newL][newA] > empty) figures[board[newL][newA]] = "00";
                board[oldL][oldA] = empty;
                board[newL][newA] = i;
                figures[i] = name.right(2);
                QString sqBeg = toString(oldA) + QString::number(8 - oldL);
                QString sqEnd = toString(newA) + QString::number(8 - newL);
                Move * translatedMove = new Move(moveNum, move->getColor(), move->getName(), sqBeg, sqEnd);
                return translatedMove;
            }
        }
    }
    throw -4;
}

Move * TranslateBoard::moveQueen(int moveNum, Move *move) {
    bool ok;
    QString name;
    int len = move->getName().length();
    if (move->getName().right(1) == "+") {
        --len;
        name = move->getName().left(len);
    } else {
        name = move->getName();
    }
    int newA = toInt(name.right(2));
    int newL = 8 - name.right(1).toInt(&ok, 10);
    if (ok == false) {
        throw -1;
    }
    if ((name.at(len-3) == "x") && (board[newL][newA] == empty)) {
        throw -3;
    }
    if (!(name.at(len-3) == "x") && !(board[newL][newA] == empty)) {
        throw -2;
    }
    if (move->getColor() == "black") {
        int oldA = toInt(figures[q]);
        int oldL = 8-figures[q].right(1).toInt(&ok, 10);
        if (ok == false)  {
            throw -1;
        }
        if ((oldA - newA == oldL - newL) || (oldA - newA == newL - oldL) ||
                (newA - oldA == newL - oldL) || (newA - oldA == newL - oldL) ||
                (newA == oldA) || (newL == oldL)){
            if (board[newL][newA] > empty) figures[board[newL][newA]] = "00";
            board[oldL][oldA] = empty;
            board[newL][newA] = q;
            figures[q] = name.right(2);
            QString sqBeg = toString(oldA) + QString::number(8 - oldL);
            QString sqEnd = toString(newA) + QString::number(8 - newL);
            Move * translatedMove = new Move(moveNum, move->getColor(), move->getName(), sqBeg, sqEnd);
            return translatedMove;
        }
    } else {
        int oldA = toInt(figures[Q]);
        int oldL = 8-figures[Q].right(1).toInt(&ok, 10);
        if (ok == false)  {
            throw -1;
        }
        if ((oldA - newA == oldL - newL) || (oldA - newA == newL - oldL) ||
                (newA - oldA == newL - oldL) || (newA - oldA == newL - oldL) ||
                (newA == oldA) || (newL == oldL)){
            if (board[newL][newA] > empty) figures[board[newL][newA]] = "00";
            board[oldL][oldA] = empty;
            board[newL][newA] = Q;
            figures[Q] = name.right(2);
            QString sqBeg = toString(oldA) + QString::number(8 - oldL);
            QString sqEnd = toString(newA) + QString::number(8 - newL);
            Move * translatedMove = new Move(moveNum, move->getColor(), move->getName(), sqBeg, sqEnd);
            return translatedMove;
        }
    }
    throw -4;
}

Move * TranslateBoard::moveKing(int moveNum, Move *move) {
    bool ok;
    QString name;
    int len = move->getName().length();
    if (move->getName().right(1) == "+") {
        --len;
        name = move->getName().left(len);
    } else {
        name = move->getName();
    }
    int newA = toInt(name.right(2));
    int newL = 8 - name.right(1).toInt(&ok, 10);
    if (ok == false) {
        throw -1;
    }
    if ((name.at(len-3) == "x") && (board[newL][newA] == empty)) {
        throw -3;
    }
    if (!(name.at(len-3) == "x") && !(board[newL][newA] == empty)) {
        throw -2;
    }
    if (move->getColor() == "black") {
        int oldA = toInt(figures[k]);
        int oldL = 8-figures[k].right(1).toInt(&ok, 10);
        if (ok == false) {
            throw -1;
        }
        if ((abs(oldL - newL) <= 1) && (abs(oldA - newA) <= 1)) {
            if (board[newL][newA] > empty) figures[board[newL][newA]] = "00";
            board[oldL][oldA] = empty;
            board[newL][newA] = k;
            figures[k] = name.right(2);
            QString sqBeg = toString(oldA) + QString::number(8 - oldL);
            QString sqEnd = toString(newA) + QString::number(8 - newL);
            Move * translatedMove = new Move(moveNum, move->getColor(), move->getName(), sqBeg, sqEnd);
            return translatedMove;
        }
    } else {
        int oldA = toInt(figures[K]);
        int oldL = 8-figures[K].right(1).toInt(&ok, 10);
        if (ok == false)  {
            throw -1;
        }
        if ((abs(oldL - newL) <= 1) && (abs(oldA - newA) <= 1)) {
            if (board[newL][newA] > empty) figures[board[newL][newA]] = "00";
            board[oldL][oldA] = empty;
            board[newL][newA] = K;
            figures[K] = name.right(2);
            QString sqBeg = toString(oldA) + QString::number(8 - oldL);
            QString sqEnd = toString(newA) + QString::number(8 - newL);
            Move * translatedMove = new Move(moveNum, move->getColor(), move->getName(), sqBeg, sqEnd);
            return translatedMove;
        }
    }
    throw -4;
}

Move * TranslateBoard::castling(int moveNum, Move *move) {
    QString name;
    int len = move->getName().length();
    if (move->getName().right(1) == "+") {
        --len;
        name = move->getName().left(len);
    } else {
        name = move->getName();
    }
    if ((len == 3) && (move->getColor() == "black"))  {
        figures[k] = "g8";
        figures[r2] = "f8";
        board[0][4] = empty;
        board[0][5] = r2;
        board[0][6] = k;
        board[0][7] = empty;
        Move * translatedMove = new Move(moveNum, move->getColor(), move->getName(), "e8", "g8", "h8", "f8");
        return translatedMove;
    } else if ((len == 5) && (move->getColor() == "black")) {
        figures[k] = "c8";
        figures[r1] = "d8";
        board[0][0] = empty;
        board[0][2] = k;
        board[0][3] = r1;
        board[0][4] = empty;
        Move * translatedMove = new Move(moveNum, move->getColor(), move->getName(), "e8", "c8", "a8", "d8");
        return translatedMove;
    } else if ((len == 3) && (move->getColor() == "white")) {
        figures[K] = "g1";
        figures[R2] = "f1";
        board[7][4] = empty;
        board[7][5] = R2;
        board[7][6] = K;
        board[7][7] = empty;
        Move * translatedMove = new Move(moveNum, move->getColor(), move->getName(), "e1", "g1", "h1", "f1");
        return translatedMove;
    } else {
        figures[K] = "c1";
        figures[R1] = "d1";
        board[7][0] = empty;
        board[7][2] = K;
        board[7][3] = R1;
        board[7][4] = empty;
        Move * translatedMove = new Move(moveNum, move->getColor(), move->getName(), "e1", "c1", "a1", "d1");
        return translatedMove;
    }
}

void TranslateBoard::debug(int board[8][8]) {
    QString boardDebug[8][8];
    for (int i = 0; i < 8; ++i) {
        for (int k = 0; k < 8; ++k) {
            int cu = board[i][k];
            if (cu < 0)
                boardDebug[i][k] = "  "; else
            if (cu == 0)
                boardDebug[i][k] = "rr"; else
            if (cu == 1)
                boardDebug[i][k] = "nn"; else
            if (cu == 2)
                boardDebug[i][k] = "bb"; else
            if (cu == 3)
                boardDebug[i][k] = "qq"; else
            if (cu == 4)
                boardDebug[i][k] = "kk"; else
            if (cu == 5)
                boardDebug[i][k] = "bb"; else
            if (cu == 6)
                boardDebug[i][k] = "nn"; else
            if (cu == 7)
                boardDebug[i][k] = "rr"; else
            if (cu < 16)
                boardDebug[i][k] = "pp"; else
            if (cu < 24)
                boardDebug[i][k] = "PP"; else
            if (cu == 24)
                boardDebug[i][k] = "RR"; else
            if (cu == 25)
                boardDebug[i][k] = "NN"; else
            if (cu == 26)
                boardDebug[i][k] = "BB"; else
            if (cu == 27)
                boardDebug[i][k] = "QQ"; else
            if (cu == 28)
                boardDebug[i][k] = "KK"; else
            if (cu == 29)
                boardDebug[i][k] = "BB"; else
            if (cu == 30)
                boardDebug[i][k] = "NN"; else
            if (cu == 31)
                boardDebug[i][k] = "RR";
        }
    }
    for (int l = 0; l < 8; ++l)
    {   qDebug() << boardDebug[l][0] << boardDebug[l][1] << boardDebug[l][2] << boardDebug[l][3] << boardDebug[l][4] << boardDebug[l][5] << boardDebug[l][6] << boardDebug[l][7];
    }
}

TranslateBoard::~TranslateBoard() {

}

